﻿using System.Linq;
using AdventureWorks.Domain;
using NHibernate;
using NHibernate.Linq;
using AdventureWorks.DataAccess.Utils;
using AdventureWorks.DataAccess.SearchCriterias;
using System;

namespace AdventureWorks.DataAccess.repository
{
    public class ProductRepository : BaseRepository<Product>, IProductRepository
    {

        public IQueryable<Product> GetProducts(ISession session,  ProductSearchCriteria searchCriteria)
        {
            return session.Query<Product>()
                .NullableWhere(x => x.Name == searchCriteria.Name)
                .NullableWhere(x => x.ProductNumber == searchCriteria.ProductNumber)
                .NullableWhere(x => x.Color == searchCriteria.Color)
                .NullableWhere(x => x.StandardCost == searchCriteria.StandardCost)
                .NullableWhere(x => x.SubCategory.Name == searchCriteria.SubCategory)
                .NullableWhere(x => (int)x.SubCategory.Category == searchCriteria.Category);
        }
        
    }
}
